package steed.netty.server;

import io.netty.channel.ChannelHandlerContext;
import steed.netty.module.BaseMsg;
import steed.netty.module.LoginMsg;
import steed.util.base.BaseUtil;
import steed.util.base.PropertyUtil;

public class LoginEngine implements NettyEngine{

	@Override
	public void dealMessage(BaseMsg baseMsg,ChannelHandlerContext channelHandlerContext) {
		LoginMsg loginMsg = (LoginMsg) baseMsg;
		 if(loginSuccess(loginMsg)){
             //登录成功,把channel存到服务端的map中
             NettyChannelMap.onLogin(loginMsg, channelHandlerContext.channel());
             BaseUtil.getLogger().debug("客户端Id"+loginMsg.getClientId()+",以用户名:"+loginMsg.getUserName()+" 登录成功");
         }		
	}
	
	protected boolean loginSuccess(LoginMsg loginMsg) {
		return PropertyUtil.getConfig("netty.userName").equals(loginMsg.getUserName())&&PropertyUtil.getConfig("netty.password").equals(loginMsg.getPassword());
	}

}
